// Decompiled by GOOSIN CO,LTD Copyright 2010 Pavel Kouznetsov.
// home page: http://www.Goosin.net
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   dealwith_ok.java

package qcs.intrmanufacture;

import include.nseer_cookie.counter;
import include.nseer_db.nseer_db_backup1;
import java.io.IOException;
import java.sql.ResultSet;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import javax.servlet.jsp.JspFactory;

public class dealwith_ok extends HttpServlet
{

	public dealwith_ok()
	{
	}

	public synchronized void service(HttpServletRequest request, HttpServletResponse response)
		throws IOException, ServletException
	{
		HttpSession dbSession = request.getSession();
		JspFactory _jspxFactory = JspFactory.getDefaultFactory();
		javax.servlet.jsp.PageContext pageContext = _jspxFactory.getPageContext(this, request, response, "", true, 8192, true);
		ServletContext dbApplication = dbSession.getServletContext();
		try
		{
			HttpSession session = request.getSession();
			ServletContext context = session.getServletContext();
			String path = context.getRealPath("/");
			counter count = new counter(dbApplication);
			nseer_db_backup1 qcs_db = new nseer_db_backup1(dbApplication);
			if (qcs_db.conn((String)dbSession.getAttribute("unit_db_name")))
				try
				{
					String qcs_id = request.getParameter("qcs_id");
					String dealwith_tag = request.getParameter("dealwith_tag");
					String apply_id = request.getParameter("apply_id");
					String qualified_amount = request.getParameter("qualified");
					String unqualified_amount = request.getParameter("unqualified");
					String qcs_amount = request.getParameter("qcs_amount");
					String sql = "";
					sql = (new StringBuilder("select id from qcs_intrmanufacture where qcs_id='")).append(qcs_id).append("' and dealwith_tag='0'").toString();
					ResultSet rs = qcs_db.executeQuery(sql);
					if (rs.next())
					{
						sql = (new StringBuilder("select intrmanufacture_id,provider_id,provider_name from qcs_apply where apply_id='")).append(apply_id).append("'").toString();
						rs = qcs_db.executeQuery(sql);
						if (rs.next())
						{
							String intrmanufacture_id = rs.getString("intrmanufacture_id");
							String provider_id = rs.getString("provider_id");
							String provider_name = rs.getString("provider_name");
							sql = (new StringBuilder("update qcs_intrmanufacture set dealwith_tag='")).append(dealwith_tag).append("' where qcs_id='").append(qcs_id).append("'").toString();
							qcs_db.executeUpdate(sql);
							sql = (new StringBuilder("update stock_gather set qcs_dealwith_tag='")).append(dealwith_tag).append("' where reasonexact='").append(intrmanufacture_id).append("' and reasonexact_details='").append(provider_name).append("'").toString();
							qcs_db.executeUpdate(sql);
							switch (Integer.parseInt(dealwith_tag))
							{
							default:
								break;

							case 1: // '\001'
								sql = (new StringBuilder("update fund_fund set qcs_dealwith_tag='")).append(dealwith_tag).append("' where reasonexact='").append(intrmanufacture_id).append("' and funder_id='").append(provider_id).append("'").toString();
								qcs_db.executeUpdate(sql);
								sql = (new StringBuilder("update intrmanufacture_details set qcs_dealwith_tag='")).append(dealwith_tag).append("' where intrmanufacture_id='").append(intrmanufacture_id).append("' and provider_id='").append(provider_id).append("'").toString();
								qcs_db.executeUpdate(sql);
								break;

							case 2: // '\002'
								String price_percent = request.getParameter("price_percent");
								sql = (new StringBuilder("update intrmanufacture_details set qcs_dealwith_tag='")).append(dealwith_tag).append("',price_percent='").append(price_percent).append("' where intrmanufacture_id='").append(intrmanufacture_id).append("' and provider_id='").append(provider_id).append("'").toString();
								qcs_db.executeUpdate(sql);
								break;

							case 3: // '\003'
								double executing_cost_price_sum = 0.0D;
								sql = (new StringBuilder("select demand_cost_price_sum from fund_fund where reasonexact='")).append(intrmanufacture_id).append("' and funder_id='").append(provider_id).append("'").toString();
								rs = qcs_db.executeQuery(sql);
								if (rs.next())
									executing_cost_price_sum = (rs.getDouble("demand_cost_price_sum") * Double.parseDouble(qualified_amount)) / Double.parseDouble(qcs_amount);
								sql = (new StringBuilder("select qualified_amount from stock_gather where reasonexact='")).append(intrmanufacture_id).append("' and reasonexact_details='").append(provider_name).append("'").toString();
								rs = qcs_db.executeQuery(sql);
								if (!rs.next())
									break;
								Double qualified_amount_temp = Double.valueOf(Double.parseDouble(qualified_amount) + rs.getDouble("qualified_amount"));
								sql = (new StringBuilder("update stock_gather set qualified_amount='")).append(qualified_amount_temp).append("' where reasonexact='").append(intrmanufacture_id).append("' and reasonexact_details='").append(provider_name).append("'").toString();
								qcs_db.executeUpdate(sql);
								unqualified_amount = unqualified_amount.equals("0") ? "" : unqualified_amount;
								sql = (new StringBuilder("update qcs_apply_details set qcs_tag='0',demand_amount='")).append(unqualified_amount).append("',limit_tag='1' where apply_id='").append(apply_id).append("'").toString();
								qcs_db.executeUpdate(sql);
								if (unqualified_amount.equals(""))
								{
									sql = (new StringBuilder("update fund_fund set qcs_dealwith_tag='1',executing_cost_price_sum='")).append(executing_cost_price_sum).append("' where reasonexact='").append(intrmanufacture_id).append("' and funder_id='").append(provider_id).append("'").toString();
									qcs_db.executeUpdate(sql);
									sql = (new StringBuilder("update intrmanufacture_details set qcs_dealwith_tag='")).append(dealwith_tag).append("' where intrmanufacture_id='").append(intrmanufacture_id).append("' and provider_id='").append(provider_id).append("'").toString();
									qcs_db.executeUpdate(sql);
								}
								break;

							case 4: // '\004'
								sql = (new StringBuilder("update qcs_apply_details set qcs_tag='0' where apply_id='")).append(apply_id).append("'").toString();
								qcs_db.executeUpdate(sql);
								break;
							}
							sql = (new StringBuilder("select id from intrmanufacture_details where intrmanufacture_id='")).append(intrmanufacture_id).append("' and qcs_dealwith_tag='0'").toString();
							rs = qcs_db.executeQuery(sql);
							if (!rs.next())
							{
								sql = (new StringBuilder("update intrmanufacture_intrmanufacture set gather_tag='3' where intrmanufacture_id='")).append(intrmanufacture_id).append("'").toString();
								qcs_db.executeUpdate(sql);
							}
						}
						response.sendRedirect("qcs/intrmanufacture/dealwith_ok.jsp?finished_tag=0");
					} else
					{
						response.sendRedirect("qcs/intrmanufacture/dealwith_ok.jsp?finished_tag=2");
					}
					qcs_db.commit();
					qcs_db.close();
				}
				catch (Exception ex)
				{
					ex.printStackTrace();
					response.sendRedirect("qcs/intrmanufacture/dealwith_ok.jsp?finished_tag=1");
				}
			else
				response.sendRedirect("error_conn.htm");
		}
		catch (Exception ex)
		{
			ex.printStackTrace();
		}
	}
}
